/*
 * reddirect
 * automatic redirection for sites that don't work with reddit toolbar
 *
 * by Minsang Kim
 * http://minsang.wordpress.com
 *
 * Copyright (c) 2011 Minsang Kim. All rights reserved.
 */

// requries jquery

function decode(input) {
    if (!input) {
        return [];
    }
    var splitted = input.split("\n");
    
    var trimmed = [];
    for (var i = 0; i < splitted.length; i++) {
        var line = $.trim(splitted[i]);
        if (line.length > 0) {
            trimmed.push(line);
        }
    }
    
    return trimmed;
}

function encode(input) {
    if (!input) {
        return [];
    }
    
    var string = "";
    
    for (var i = 0; i < input.length; i++) {
        string += input[i];
        if (i != input.length - 1) {
            string += "\n";
        }
    }
    
    return string;
}

function init(forced) {
    // skip run_once check if force is true
    if (!forced && localStorage["run_once"]) {
        // already ran once, don't do any init
        return;
    }
    localStorage.clear();
    
    // first time running (either options or background) - set some defaults
    localStorage["whitelist"] = encode([
        "static.flickr.com"
    ]);

    localStorage["blacklist"] = encode([
        "youtube.com",
        "twitter.com",
        "flickr.com",
        "stackoverflow.com"
    ]);
    
    localStorage["run_once"] = true;
}


